<template>
    <div class="frame">
        <el-dialog
        :title=title
        :visible.sync="showIn"
        width="440px"
        :before-close="closeFrame"
        >
          <div  class="password">
            <p>{{$t("ac.password")}}</p>
            <input type="password"  :placeholder="this.$t('ac.passwordPlaceholder')" v-model="secret">
            <button @click="confirm">{{$t("ac.sumbit")}}</button>
          </div>
    </el-dialog>
    </div>
</template>
<script>

  import  {buyram,delegatebw,selectOuterDatx} from  '../../service/datxService'
  import {validateSecret,getforNumber} from '../../utils/commonUtils'

export default{

    data(){
        return{
             ifpassword:false,
             datxDetail:{},
             showIn:true,
             coinName:'',
             account:'', //账号
             title: '抵押资源',
             buyer:'',  // 购买者
             receiver:'',// 接收者
             secret:'',//密码
             from:'',// 购买者

         }
    },

   props: ['quant','stake_net_quantity','stake_cpu_quantity'],

   created(){
    this.getMessage()
   },

   methods:{
     getMessage(){
       this.datxDetail = JSON.parse(window.sessionStorage.getItem("walletdetail"));
       this.account=this.datxDetail.name;
       this.buyer=this.datxDetail.name;
       this.receiver=this.datxDetail.name;
       this.from=this.datxDetail.name;

     },

      closeFrame(){
         this.$emit('morgageListen',false)
      },

     // 确认密码，私钥的
      confirm(){

          if(validateSecret(this.secret)){
            let obj=selectOuterDatx(this.datxDetail.name,this.secret)
            let privateKey=obj.privateKey
               if(privateKey){
                 if(this.quant>0){
                   buyram(this.buyer,this.receiver,getforNumber(this.quant)+" DATX",privateKey,(erro,state) =>{
                     console.log(erro,state)
                     if(erro){
                       this.$message.error('erro')
                     }else {
                       this.$message.success("操作成功")
                     }
                   })
                 }
                 if(this.stake_net_quantity>0||this.stake_cpu_quantity>0){
                   delegatebw(this.from,this.receiver,getforNumber(this.stake_net_quantity)+" DATX",getforNumber(this.stake_cpu_quantity)+" DATX",0,privateKey,(erro,data) =>{
                     console.log(erro,data)
                     if(erro){
                       this.$message.error('erro')
                     }else {
                       this.$message.success("操作成功")
                     }
                   })
                 }
               }else{
                 this.$message.error('私钥不存在')
               }

          }else {
            this.$message.error(" 验证密码错误")
          }
         this.$emit('morgageListen',false)
       }
    } 
}
</script>
<style lang="less" scoped>
.frame{
   .content{
        .content-input{
            padding: 10px 20px;
            margin-top: 20px;
            background:#fbfbfc;; 
            color: #666666;
            input{
            width: 349px;
            height: 34px;
            padding: 0 10px;
            border-radius: 4px;
            border: solid 1px #eeeeee;
            background-color: #ffffff; 
            }
            input::-webkit-input-placeholder {
            font-size: 12px;
            color: #c5c7cb;
            
          }
          .disabled{
            background-color: #f5f7fa;
            border-color: #e4e7ed;
            color: #c0c4cc;
            cursor: not-allowed;
          }
            .balance{
            margin-bottom: 15px;  
            }
            .transfer{
                padding-bottom: 20px;
                border-bottom: 1px solid #eaedf5;
                div{
                    line-height: 34px;
                }
            }
            .memo{
                padding-top: 20px 
            }
            .adress{
                margin-bottom: 15px;   
            }
        
        }
        .content-button{ 
            margin: 22px 0;
        button{
            color:#fff;
            width: 400px;
            margin:  0 auto;
            display: block;
            border-radius: 4px;
            line-height:32px;
            text-align: center;
            background-color: #98889b;
            outline: none;
            border: none;
            cursor: pointer;
        }
        button:hover{
            opacity: .8;
        }   
        }
    }
   .password{
    padding: 0 20px;
      p{
        color: #666666;
        padding:15px 0;
      }
      input{
        width: 100%;
        height: 34px;
        padding: 0 10px;
        border-radius: 4px;
        border: solid 1px #eeeeee;
        background-color: #ffffff;
      }
      input::-webkit-input-placeholder {
        font-size: 12px;
        color: #c5c7cb;
      }
      button{
        width: 100%;
        margin: 30px 0 10px;
        color: #fff;
        border-radius: 4px;
        text-align: center;
        line-height: 40px;
        background: #98889b;
        outline: none;
        cursor: pointer;
      }
      button:hover{
        opacity: .8;
     }
      div{
        margin: 0px;
        p{
          padding: 5px 0;
          text-align: center;
        }
        span{
          font-size: 12px;
          color: #98889b;
        }
      }
  }
}

</style>
<style lang="less" >
.frame{
    .el-dialog__wrapper{ 
        .el-dialog{
                    border-radius: 8px;
            }
            .el-dialog__header{
                border-bottom:1px solid #eaedf5;
                color:#000000;
                font-size: 18px;
                font-weight: bold;
                padding:20px;
            }
            .el-dialog__body{
                padding:30px 0;
            }
            .el-dialog__headerbtn .el-dialog__close{
                color: #666666;
                
        }
    }          
}
</style>


